﻿#region Copyright and License Notice
// Copyright (C)2010-2016 - Rob Levine and other contributors
// http://configgen.codeplex.com
// 
// This file is part of ConfigGen.
// 
// ConfigGen is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// ConfigGen is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License and 
// the GNU Lesser General Public License along with ConfigGen.  
// If not, see <http://www.gnu.org/licenses/>
#endregion

using System.Collections.Generic;
using ConfigGen.Utilities.Extensions.System.Collections.Generic;

namespace ConfigGen.Core
{
    /// <summary>
    /// Encapsulates token count statistics generated during confiugration file generation.
    /// </summary>
    public class TokenCounts
    {
        private readonly IDictionary<string, int> _unrecognisedTokenCounts;
        private readonly IDictionary<string, int> _tokenUseCounts;

        /// <summary>
        /// 
        /// </summary>
        public TokenCounts()
            : this(new Dictionary<string, int>(), new Dictionary<string, int>())
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tokenUseCounts"></param>
        /// <param name="unrecognisedTokenCounts"></param>
        public TokenCounts(IDictionary<string, int> tokenUseCounts, IDictionary<string, int> unrecognisedTokenCounts)
        {
            _tokenUseCounts = tokenUseCounts;
            _unrecognisedTokenCounts = unrecognisedTokenCounts;
        }

        /// <summary>
        /// Gets a dictionary containing the tokens that were encountered, but not in the supplied machine settings collection, during 
        /// the generation of a config file. The key is the name of the token, and the value is the number of times it was encountered. 
        /// </summary>
        public IDictionary<string, int> UnrecognisedTokenCounts
        {
            get { return _unrecognisedTokenCounts; }
        }

        /// <summary>
        /// Gets a dictionary containing the tokens that were encountered during the generation of a config file. The key is the name of 
        /// the token, and the value is the number of times it was encountered. 
        /// </summary>
        public IDictionary<string, int> TokenUseCounts
        {
            get { return _tokenUseCounts; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void IncrementUnrecognisedTokenCount(object sender, TokenEventArgs args)
        {
            UnrecognisedTokenCounts.IncrementCountForKey(args.TokenName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void IncrementTokenUseCount(object sender, TokenEventArgs args)
        {
            TokenUseCounts.IncrementCountForKey(args.TokenName);
        }
    }
}